package com.mach.platform.domain.iot;

import com.google.common.base.Splitter;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author Administrator
 * @Description:  设备 组态 模块  小设备 组成 虚拟大设备
 * @Package: com.mach.platform.domain.iot
 * @time 2018/9/27 0027 12:50
 */
@Data
@ToString
@Entity
@Table(name = "iot_config_device")
public class IotConfigDevice implements Serializable {

	private static final long serialVersionUID = -3331487873174461827L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;

	/**
	 * 组态名称
	 */
	private String label;

	/**
	 * 组态id
	 */
	private String uuid;

	/**
	 * 设备id
	 */
	@Column(name = "dev_id", columnDefinition = "bigint(20) not null COMMENT '设备ID'")
	private Long devId;

	@Column(name = "dev_name")
	private String devName;

	/**
	 *属性字符串
	 */
	@Column(name = "properties", columnDefinition = "varchar(255) default null COMMENT '属性字符串'")
	private String properties;

	@Transient
	private List<String> dataTypes;

	public List<String> getDataTypes() {
		if (this.getProperties() == null) {
			return Collections.emptyList();
		} else {
			return Splitter.on("_").splitToList(this.getProperties());
		}
	}

}
